{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "190d7a89",
   "metadata": {},
   "source": [
    "# 2.1 匿名函数与map方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "298e2374",
   "metadata": {},
   "outputs": [],
   "source": [
    "my_func = lambda x: 2*x "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b0e76c25",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_func(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7cb9a206",
   "metadata": {},
   "outputs": [],
   "source": [
    "multi_para_func = lambda a,b :a-b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7d5501f7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "multi_para_func(1,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b4a70d08",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 6, 8, 10]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[(lambda x:2*x)(i) for i in range(6)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "77aeb9c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['0_a', '1_b', '2_c', '3_d', '4_e']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(map(lambda x, y: str(x)+'_'+y, range(5), list('abcde')))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e95d84d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 练习 ：\n",
    "name = ['小虎','小红','小明']\n",
    "age = [18,19,20]\n",
    "# 希望得到效果：\n",
    "['小虎_18','小红_19','小明_20']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "11a1efe1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['小虎_18', '小红_19', '小明_20']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# lambda   \n",
    "list(map(lambda x,y:x+'_'+str(y),name,age))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "c56fcbd2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# zip 方法\n",
    "L1, L2, L3 = list('abc'), list('def'), list('hij')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "937bde44",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('a', 'd', 'h'), ('b', 'e', 'i'), ('c', 'f', 'j')]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(zip(L1, L2, L3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "0533e3ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(('a', 'd', 'h'), ('b', 'e', 'i'), ('c', 'f', 'j'))"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tuple(zip(L1, L2, L3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fee48bdc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Defaulting to user installation because normal site-packages is not writeable\n",
      "Collecting pyecharts\n",
      "  Downloading pyecharts-2.0.2-py3-none-any.whl (146 kB)\n",
      "     ------------------------------------ 146.1/146.1 kB 177.4 kB/s eta 0:00:00\n",
      "Collecting simplejson\n",
      "  Downloading simplejson-3.18.3-cp39-cp39-win_amd64.whl (74 kB)\n",
      "     -------------------------------------- 74.9/74.9 kB 343.9 kB/s eta 0:00:00\n",
      "Requirement already satisfied: jinja2 in d:\\anaconda\\lib\\site-packages (from pyecharts) (2.11.3)\n",
      "Collecting prettytable\n",
      "  Downloading prettytable-3.6.0-py3-none-any.whl (27 kB)\n",
      "Requirement already satisfied: MarkupSafe>=0.23 in d:\\anaconda\\lib\\site-packages (from jinja2->pyecharts) (2.0.1)\n",
      "Requirement already satisfied: wcwidth in d:\\anaconda\\lib\\site-packages (from prettytable->pyecharts) (0.2.5)\n",
      "Installing collected packages: simplejson, prettytable, pyecharts\n",
      "Successfully installed prettytable-3.6.0 pyecharts-2.0.2 simplejson-3.18.3\n"
     ]
    }
   ],
   "source": [
    "!pip install pyecharts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "211cf4c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import BMap\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "c = (\n",
    "    BMap()\n",
    "    .add_schema(baidu_ak=\"FAKE_AK\", center=[120.13066322374, 30.240018034923])\n",
    "    .add(\n",
    "        \"bmap\",\n",
    "        [list(z) for z in zip(Faker.provinces, Faker.values())],\n",
    "        label_opts=opts.LabelOpts(formatter=\"{b}\"),\n",
    "    )\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"BMap-基本示例\"))\n",
    "    .render(\"bmap_base.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1ddb59e7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广东省', '北京市', '上海市', '江西省', '湖南省', '浙江省', '江苏省']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Faker.provinces"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d0324c37",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[135, 65, 45, 76, 101, 121, 59]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Faker.values()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "05083f98",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('广东省', 37, 71, 67, 88, 24),\n",
       " ('北京市', 74, 123, 138, 30, 34),\n",
       " ('上海市', 125, 131, 142, 69, 25),\n",
       " ('江西省', 118, 61, 31, 49, 59),\n",
       " ('湖南省', 71, 139, 57, 37, 99),\n",
       " ('浙江省', 98, 123, 142, 88, 98),\n",
       " ('江苏省', 91, 46, 113, 128, 116)]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(zip(Faker.provinces, Faker.values(),Faker.values(),Faker.values(),Faker.values(),Faker.values()))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d5f8f3f",
   "metadata": {},
   "source": [
    "# 读取数据"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c120e58f",
   "metadata": {},
   "source": [
    "* data/my_csv.csv\n",
    "* data/my_table.txt\n",
    "* data/my_excel.xlsx\n",
    "* data/my_table.txt\n",
    "* data/my_csv.csv\n",
    "* data/my_table.txt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "5760f41c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "4b9ed829",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col1</th>\n",
       "      <th>col2</th>\n",
       "      <th>col3</th>\n",
       "      <th>col4</th>\n",
       "      <th>col5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>a</td>\n",
       "      <td>1.4</td>\n",
       "      <td>apple</td>\n",
       "      <td>2020/1/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>b</td>\n",
       "      <td>3.4</td>\n",
       "      <td>banana</td>\n",
       "      <td>2020/1/2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6</td>\n",
       "      <td>c</td>\n",
       "      <td>2.5</td>\n",
       "      <td>orange</td>\n",
       "      <td>2020/1/5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>d</td>\n",
       "      <td>3.2</td>\n",
       "      <td>lemon</td>\n",
       "      <td>2020/1/7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   col1 col2  col3    col4      col5\n",
       "0     2    a   1.4   apple  2020/1/1\n",
       "1     3    b   3.4  banana  2020/1/2\n",
       "2     6    c   2.5  orange  2020/1/5\n",
       "3     5    d   3.2   lemon  2020/1/7"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv('my_csv.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "60aa7923",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col1</th>\n",
       "      <th>col2</th>\n",
       "      <th>col3</th>\n",
       "      <th>col4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>a</td>\n",
       "      <td>1.4</td>\n",
       "      <td>apple 2020/1/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>b</td>\n",
       "      <td>3.4</td>\n",
       "      <td>banana 2020/1/2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6</td>\n",
       "      <td>c</td>\n",
       "      <td>2.5</td>\n",
       "      <td>orange 2020/1/5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>d</td>\n",
       "      <td>3.2</td>\n",
       "      <td>lemon 2020/1/7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   col1 col2  col3             col4\n",
       "0     2    a   1.4   apple 2020/1/1\n",
       "1     3    b   3.4  banana 2020/1/2\n",
       "2     6    c   2.5  orange 2020/1/5\n",
       "3     5    d   3.2   lemon 2020/1/7"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_table('my_table.txt')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "b944e0c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col1</th>\n",
       "      <th>col2</th>\n",
       "      <th>col3</th>\n",
       "      <th>col4</th>\n",
       "      <th>col5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>a</td>\n",
       "      <td>1.4</td>\n",
       "      <td>apple</td>\n",
       "      <td>2020/1/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>b</td>\n",
       "      <td>3.4</td>\n",
       "      <td>banana</td>\n",
       "      <td>2020/1/2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6</td>\n",
       "      <td>c</td>\n",
       "      <td>2.5</td>\n",
       "      <td>orange</td>\n",
       "      <td>2020/1/5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>d</td>\n",
       "      <td>3.2</td>\n",
       "      <td>lemon</td>\n",
       "      <td>2020/1/7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   col1 col2  col3    col4      col5\n",
       "0     2    a   1.4   apple  2020/1/1\n",
       "1     3    b   3.4  banana  2020/1/2\n",
       "2     6    c   2.5  orange  2020/1/5\n",
       "3     5    d   3.2   lemon  2020/1/7"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_excel('my_excel.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "3d06159f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col2</th>\n",
       "      <th>col3</th>\n",
       "      <th>col4</th>\n",
       "      <th>col5</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>col1</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>a</td>\n",
       "      <td>1.4</td>\n",
       "      <td>apple</td>\n",
       "      <td>2020/1/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>b</td>\n",
       "      <td>3.4</td>\n",
       "      <td>banana</td>\n",
       "      <td>2020/1/2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>c</td>\n",
       "      <td>2.5</td>\n",
       "      <td>orange</td>\n",
       "      <td>2020/1/5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>d</td>\n",
       "      <td>3.2</td>\n",
       "      <td>lemon</td>\n",
       "      <td>2020/1/7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     col2  col3    col4      col5\n",
       "col1                             \n",
       "2       a   1.4   apple  2020/1/1\n",
       "3       b   3.4  banana  2020/1/2\n",
       "6       c   2.5  orange  2020/1/5\n",
       "5       d   3.2   lemon  2020/1/7"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_excel('my_excel.xlsx',index_col='col1')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "d0f3ebc6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col1</th>\n",
       "      <th>col2</th>\n",
       "      <th>col3</th>\n",
       "      <th>col5</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>col4</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>apple</th>\n",
       "      <td>2</td>\n",
       "      <td>a</td>\n",
       "      <td>1.4</td>\n",
       "      <td>2020/1/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>banana</th>\n",
       "      <td>3</td>\n",
       "      <td>b</td>\n",
       "      <td>3.4</td>\n",
       "      <td>2020/1/2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>orange</th>\n",
       "      <td>6</td>\n",
       "      <td>c</td>\n",
       "      <td>2.5</td>\n",
       "      <td>2020/1/5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>lemon</th>\n",
       "      <td>5</td>\n",
       "      <td>d</td>\n",
       "      <td>3.2</td>\n",
       "      <td>2020/1/7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        col1 col2  col3      col5\n",
       "col4                             \n",
       "apple      2    a   1.4  2020/1/1\n",
       "banana     3    b   3.4  2020/1/2\n",
       "orange     6    c   2.5  2020/1/5\n",
       "lemon      5    d   3.2  2020/1/7"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_excel('my_excel.xlsx',index_col='col4')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2e096f19",
   "metadata": {},
   "source": [
    "* 重要的文件读取方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "b2fb1046",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col1</th>\n",
       "      <th>col2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>TS</td>\n",
       "      <td>This is an apple.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>GQ</td>\n",
       "      <td>My name is Bob.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>WT</td>\n",
       "      <td>Well done!</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>PT</td>\n",
       "      <td>May I help you?</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  col1               col2\n",
       "0   TS  This is an apple.\n",
       "1   GQ    My name is Bob.\n",
       "2   WT         Well done!\n",
       "3   PT    May I help you?"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_table('my_table_special_sep.txt',sep=',',engine='python')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "d8ef3bef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col1,col2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>TS,This is an apple.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>GQ,My name is Bob.</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>WT,Well done!</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>PT,May I help you?</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              col1,col2\n",
       "0  TS,This is an apple.\n",
       "1    GQ,My name is Bob.\n",
       "2         WT,Well done!\n",
       "3    PT,May I help you?"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_table('my_table_special_sep.txt')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "40544119",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_html('https://hurun.net/zh-CN/Info/Detail?num=L9SQPH9FKJB1')[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "3d60059d",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_excel('output.xlsx',index = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "5c263f34",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_csv('output.csv',index = False,encoding='UTF8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "c8f3890a",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_html('output.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "38def051",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[    Unnamed: 0       0             1             2  \\\n",
       " 0            0  æå  æååå        ä¼ä¸   \n",
       " 1            1       1             0        æé³   \n",
       " 2            2       2             1        SpaceX   \n",
       " 3            3       3            -1  èèéå¢   \n",
       " 4            4       4             0        Stripe   \n",
       " 5            5       5            11         Shein   \n",
       " 6            6       6            15        å¸å®   \n",
       " 7            7       7             1    Databricks   \n",
       " 8            8       8             3  å¾®ä¼é¶è¡   \n",
       " 9            9       9             2  äº¬ä¸ç§æ   \n",
       " 10          10      10            11  Checkout.com   \n",
       " \n",
       "                               3                                  4          5  \\\n",
       " 0   ä»·å¼ï¼äº¿å\n",
       " äººæ°å¸ï¼  ä»·å¼ååï¼äº¿å\n",
       " äººæ°å¸ï¼     æ»é¨   \n",
       " 1                         13400                             -10050     åäº¬   \n",
       " 2                          8400                               1680  æ´æç¶   \n",
       " 3                          8000                              -2010     æ­å·   \n",
       " 4                          4100                              -2230  æ§éå±±   \n",
       " 5                          4000                               2680     å¹¿å·   \n",
       " 6                          3000                               2010  é©¬è³ä»   \n",
       " 7                          2500                                  0  æ§éå±±   \n",
       " 8                          2200                                200     æ·±å³   \n",
       " 9                          2000                                  0     åäº¬   \n",
       " 10                         1900                                870     ä¼¦æ¦   \n",
       " \n",
       "                6             7  \n",
       " 0         è¡ä¸  æç«å¹´ä»½  \n",
       " 1   ç¤¾äº¤åªä½          2012  \n",
       " 2         èªå¤©          2002  \n",
       " 3   éèç§æ          2014  \n",
       " 4   éèç§æ          2010  \n",
       " 5   çµå­åå¡          2012  \n",
       " 6      åºåé¾          2017  \n",
       " 7      å¤§æ°æ®          2013  \n",
       " 8   éèç§æ          2014  \n",
       " 9   æ°å­ç§æ          2013  \n",
       " 10  éèç§æ          2012  ]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_html('output.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "5ddf227e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Defaulting to user installation because normal site-packages is not writeable\n",
      "Requirement already satisfied: tabulate in d:\\anaconda\\lib\\site-packages (0.8.10)\n"
     ]
    }
   ],
   "source": [
    "!pip install tabulate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "15b1e9a3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "|    | 0    | 1        | 2            | 3                  | 4                      | 5      | 6        | 7        |\n",
      "|---:|:-----|:---------|:-------------|:-------------------|:-----------------------|:-------|:---------|:---------|\n",
      "|  0 | 排名 | 排名变化 | 企业         | 价值（亿元人民币） | 价值变化（亿元人民币） | 总部   | 行业     | 成立年份 |\n",
      "|  1 | 1    | 0        | 抖音         | 13400              | -10050                 | 北京   | 社交媒体 | 2012     |\n",
      "|  2 | 2    | 1        | SpaceX       | 8400               | 1680                   | 洛杉矶 | 航天     | 2002     |\n",
      "|  3 | 3    | -1       | 蚂蚁集团     | 8000               | -2010                  | 杭州   | 金融科技 | 2014     |\n",
      "|  4 | 4    | 0        | Stripe       | 4100               | -2230                  | 旧金山 | 金融科技 | 2010     |\n",
      "|  5 | 5    | 11       | Shein        | 4000               | 2680                   | 广州   | 电子商务 | 2012     |\n",
      "|  6 | 6    | 15       | 币安         | 3000               | 2010                   | 马耳他 | 区块链   | 2017     |\n",
      "|  7 | 7    | 1        | Databricks   | 2500               | 0                      | 旧金山 | 大数据   | 2013     |\n",
      "|  8 | 8    | 3        | 微众银行     | 2200               | 200                    | 深圳   | 金融科技 | 2014     |\n",
      "|  9 | 9    | 2        | 京东科技     | 2000               | 0                      | 北京   | 数字科技 | 2013     |\n",
      "| 10 | 10   | 11       | Checkout.com | 1900               | 870                    | 伦敦   | 金融科技 | 2012     |\n"
     ]
    }
   ],
   "source": [
    "print(df.to_markdown())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b5bc88b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fafc8b12",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a8d5ea7c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
